<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<c:set var="webroot" value="${pageContext.request.contextPath}" />
<html>
<head>
	<meta charset="utf-8">
	<title>借款用户列表</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="format-detection" content="telephone=no">
	<link rel="stylesheet" href="${webroot}/static/layui/css/layui.css" media="all" />
	<link rel="stylesheet" href="${webroot}/static/css/public.css" media="all" />
<style type="text/css">
 .layui-btn+.layui-btn {
    margin-left: 0px;
 }
</style>
</head>
<body class="childrenBody">
<form class="layui-form">
	<blockquote class="layui-elem-quote quoteBox">
		<form class="layui-form">
		   <input type="hidden" id="roleId" name="roleId">
			<div class="layui-inline">
				<div class="layui-input-inline">
					<input type="text" class="layui-input userName" placeholder="搜索姓名/手机号" />
				</div>
				<a class="layui-btn search_btn" data-type="reload">查询</a>
				<a class="layui-btn layui-btn-primary reset" data-type="reload">重置</a>
			</div>
			<div class="layui-inline">
				<a class="layui-btn layui-btn-normal addNews_btn">添加用户</a>
			</div>
		</form>
	</blockquote>
	<table id="newsList" lay-filter="newsList"></table>
	<!--操作-->
	<script type="text/html" id="newsListBar">
        <a class="layui-btn layui-btn-xs layui-btn-primary" lay-event="look">查看详情</a>
	</script>
</form>
<script type="text/javascript" src="${webroot}/static/layui/layui.js"></script>
<script src="${webroot}/static/js/jquery.min.js" charset="utf-8"></script>
<script>
layui.use(['form','layer','laydate','table','laytpl'],function(){
    var form = layui.form,
        layer = parent.layer === undefined ? layui.layer : top.layer,
        $ = layui.jquery,
        laydate = layui.laydate,
        laytpl = layui.laytpl,
        table = layui.table;

    //新闻列表
    var tableIns = table.render({
        elem: '#newsList',
        url : '/admin/userinfo/querypage',
        cellMinWidth : 95,
        page : true,
        height : "full-125",
        limit : 15,
        limits : [ 10, 15, 20, 25 ,30 , 50, 80, 100],
        id : "newsListTable",
        cols : [[
            {field: 'id', title: '用户编号', align:"center"},
            {field: 'userName', title: '客户姓名', align:"center"},
            {field: 'mobile', title: '客户电话', align:'center'},
            {field: 'sex', title: '性别', align:'center',templet : function(d) {
            	var str = '';
            	if (d.sex == 0) {
            		str = '男';
            	}else if(d.sex == 1){
            		str = '女';
            	}
            	return str;
            }},
            {field: 'mailbox', title: '借款人邮箱', align:'center'},
            {title: '操作', templet:'#newsListBar',fixed:"right",align:"center"}
        ]]
    });

    //是否置顶
    form.on('switch(newsTop)', function(data){
        var index = layer.msg('修改中，请稍候',{icon: 16,time:false,shade:0.8});
        setTimeout(function(){
            layer.close(index);
            if(data.elem.checked){
                layer.msg("置顶成功！");
            }else{
                layer.msg("取消置顶成功！");
            }
        },500);
    })

	form.on('select', function(data){
	  $("#roleId").val(data.value); //得到被选中的值]
	}); 
    
    //搜索【此功能需要后台配合，所以暂时没有动态效果演示】
    $(".search_btn").on("click",function(){
         table.reload("newsListTable",{
              page: {
                    curr: 1 //重新从第 1 页开始
              },
              where: {
            	  key: $(".userName").val()
              }
         });
    });
    
    //重置
    $(".reset").on("click",function(){
    	document.location.href="/admin/userinfo/showlist";
       /*  $("#userName").val("");
        table.reload("newsListTable",{
            page: {
                  curr: 1 
            },
            where: {
            	key: ''
            }
       }); */
    });

    //添加成员
    function addNews(edit){
    	if(edit == undefined){
    		window.location.href="/admin/userinfo/detail?show="+1;
    	}else{
    		window.location.href="/admin/userinfo/detail?id="+edit.id+"&show="+1;
		}
    }
    $(".addNews_btn").click(function(){
        addNews();
    })

    //列表操作
    table.on('tool(newsList)', function(obj){
        var layEvent = obj.event,
            data = obj.data;
        if(layEvent === 'look'){ //预览
        	addNews(data);
        }
    }); 

})
</script>
</body>
</html>